package com.systar.activity.state;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;

import com.castsoftware.java.FileExplorer;
import com.systar.activity.events.AbstractActivityEvent;
import com.systar.activity.events.IActivityEvent;
import com.systar.activity.monitor.ActivitySource;

public class FileActivity extends AbstractActivityEvent
{
	private final File file;
	private BufferedReader reader;

	public FileActivity(ActivitySource source, File file)
	{
		this.file = file;
		setSource(source);
		reader = null;
	}

	public File getFile()
	{
		return file;
	}

	@Override
	public String getType()
	{
		return "FILE";
	}

	@Override
	public String getMessage()
	{
		return file.getAbsolutePath();
	}

	@Override
	public void concat(IActivityEvent other)
	{
		// None
	}

	public BufferedReader getReader() throws IOException
	{
		if (reader == null)
		{
			reader = FileExplorer.getInstance().getFileReader(getFile());
		}
		return reader;
	}
}
